package com.pp.controller;

import com.pp.common.pojo.Comment;
import com.pp.common.pojo.Post;
import com.pp.common.vo.CommentVo;
import com.pp.common.vo.SysResult;
import com.pp.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/comment")
@CrossOrigin
public class CommentController {
    @Autowired
    private CommentService commentService;

    /**
     * 基于帖子id查询所有帖子的评论
     * @param id
     * @return
     */
    @GetMapping("/selectComment/{id}")
    public SysResult selectComment(@PathVariable Integer id){
        List<CommentVo> commentList = commentService.selectComment(id);
        return SysResult.success(commentList);
    }
    /**
     * 用户对帖子评论
     */
    @PostMapping("/insterComment")
    public SysResult insterComment(@RequestBody Comment comment){
        if (comment.getCommentContent().isEmpty())
            return SysResult.fail();
        commentService.userByname(comment);
        return SysResult.success();
    }
}
